function calculate(stocks) {
  let max = 0;
  for (let i = 0; i < stocks.length; i++) {
    for (let j = i + 1; j < stocks.length; j++) {
      if (stocks[j] - stocks[i] > max) {
        max = stocks[j] - stocks[i];
      }
    }
  }
  return max;
}

console.log(calculate([7, 1, 5, 3, 6, 4]));
